#include "intro.h"
#include "mainWindow.h"
#include <iostream>
//debuging-----------------------------
//#define DEBUGING_LOAD
#ifdef DEBUGING_INTRO
#include <gtkmm/main.h>
int main(int argc, char* argv[]){
	Gtk::Main kit(argc, argv);
	introWin window;
	Gtk::Main::run(window);
}
#endif
#ifdef DEBUGING_NEW
#include <gtkmm/main.h>
int main(int argc, char* argv[]){
	Gtk::Main kit(argc, argv);
	newGameWin window;
	Gtk::Main::run(window);
}
#endif
#ifdef DEBUGING_LOAD
#include <gtkmm/main.h>
int main(int argc, char* argv[]){
	Gtk::Main kit(argc, argv);
	loadGameWin window;
	Gtk::Main::run(window);
}
#endif
//-------------------------------------

//introWin-----------------------------
//constructor
introWin::introWin() : Gtk::Table(3, 3, true){
	//border width
	set_border_width(10);
        //do_intro();
}
introWin::~introWin(){
}
//do funtions-----------
// swap the windows
// about
//----------------------
void introWin::do_intro(){
        Glib::RefPtr<Gdk::Window> win = get_window();
        //make widgets
	Gtk::Alignment* newAlign = new Gtk::Alignment(0.2, 0.8, 0.0, 0.0);
	Gtk::Alignment* loadAlign = new Gtk::Alignment(0.8, 0.8, 0.0, 0.0);
	Gtk::Button* newGame = new Gtk::Button("New Game");
	Gtk::Button* loadGame = new Gtk::Button("Load Game");
	Gtk::Label* introLabel = new Gtk::Label("Stalemate\n\tA game of tactics\n\t\tBy GreatCow productions");
	//add signals
	newGame->signal_clicked().connect(sigc::mem_fun(*this, &introWin::newGamePress));
	loadGame->signal_clicked().connect(sigc::mem_fun(*this, &introWin::loadGamePress));
	//create hierarchy
	newAlign->add(*newGame);
	loadAlign->add(*loadGame);
	attach(*introLabel, 0, 3, 0, 2);
	attach(*newAlign, 0, 1, 2, 3);
	attach(*loadAlign, 2, 3, 2, 3);
	//show
	introLabel->show();
	newAlign->show();
	newGame->show();
	loadAlign->show();
	loadGame->show();

        //show the widgets
        this->set_visible(true);

        //store pointers
        ptrs.push_back(newAlign);
        ptrs.push_back(loadAlign);
        ptrs.push_back(newGame);
        ptrs.push_back(loadGame);
        ptrs.push_back(introLabel);
}

void introWin::do_new_game(){
        Glib::RefPtr<Gdk::Window> win = get_window();
        //make widgets
	Gtk::HBox* buttonbox = new Gtk::HBox(false, 0);
	Gtk::Alignment* newAlign = new Gtk::Alignment(0.2, 0.8, 0.0, 0.0);
	Gtk::Alignment* backAlign = new Gtk::Alignment(0.8, 0.8, 0.0, 0.0);
	Gtk::Button* newGame = new Gtk::Button("Start Game");
	Gtk::Button* back = new Gtk::Button("Back");
	nameMenu* nChooser = new nameMenu();
	//assign actions
	newGame->signal_clicked().connect(sigc::mem_fun(*this, &introWin::newGameAction));
	back->signal_clicked().connect(sigc::mem_fun(*this, &introWin::introAction));
	//add strings
        /*
	string* str;
	gameData* dat = gameData::getGameData();
	int size = dat->entries(MAPDIR, &str);
	for(int i = 0; i < size; i++){
		//nChooser->addNames(str[i]);
	}
         */
	//attach
	newAlign->add(*newGame);
	backAlign->add(*back);
	attach(*nChooser, 0,3,0,2);
        attach(*newAlign, 0,1,2,3);
        attach(*backAlign, 2,3,2,3);

	//show
	buttonbox->show();
	newAlign->show();
	backAlign->show();
	nChooser->show();
	back->show();
	newGame->show();

        //save pointers
        ptrs.push_back(buttonbox);
        ptrs.push_back(newAlign);
        ptrs.push_back(backAlign);
        ptrs.push_back(newGame);
        ptrs.push_back(back);
        ptrs.push_back(nChooser);
//        ptrs.push_back(dat);
  //      ptrs.push_back(str);
}
void introWin::do_load_game(){
        //create Widgets
	Gtk::Alignment* loadAlign = new Gtk::Alignment(0.2, 0.8, 0.0, 0.0);
	Gtk::Alignment* backAlign = new Gtk::Alignment(0.8, 0.8, 0.0, 0.0);
	Gtk::Button* loadGame = new Gtk::Button("Load Game");
	Gtk::Button* back = new Gtk::Button("Back");
	nameMenu* loadLabel = new nameMenu();

        //add signals
	loadGame->signal_clicked().connect(sigc::mem_fun(*this, &introWin::introAction));
	back->signal_clicked().connect(sigc::mem_fun(*this, &introWin::introAction));
	//attach
	loadAlign->add(*loadGame);
	backAlign->add(*back);

        attach(*loadLabel, 0, 3, 0, 2);
	attach(*loadAlign, 0, 1, 2, 3);
	attach(*backAlign, 2, 3, 2, 3);
	//show
	loadAlign->show();
	backAlign->show();
	loadLabel->show();
	back->show();
	loadGame->show();

        //save pointers
        ptrs.push_back(loadAlign);
        ptrs.push_back(backAlign);
        ptrs.push_back(loadGame);
        ptrs.push_back(back);
        ptrs.push_back(loadLabel);
}
//buton actions---------
void introWin::newGamePress(){
    clearMem();
    do_new_game();
}
void introWin::loadGamePress(){
    clearMem();
    do_load_game();
}
void introWin::newGameAction(){
    clearMem();
    game::getGame()->do_game();
}
void introWin::loadGameAction(){
    clearMem();
}
void introWin::introAction(){
    clearMem();
    do_intro();
}
//clear the memory
void introWin::clearMem(){
    for(int i = 0; i < ptrs.size(); i++){
        ptrs[i]->set_visible(false);
        delete ptrs[i];
    }
    ptrs.clear();
}
//=====================================
